package com.xjy.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xjy.common.core.mybatisplus.core.ServicePlusImpl;
import com.xjy.common.core.page.PagePlus;
import com.xjy.common.core.page.TableDataInfo;
import com.xjy.common.utils.PageUtils;
import com.xjy.system.domain.SysPaycolType;
import com.xjy.system.domain.bo.SysPaycolTypeAddBo;
import com.xjy.system.domain.bo.SysPaycolTypeEditBo;
import com.xjy.system.domain.bo.SysPaycolTypeQueryBo;
import com.xjy.system.domain.vo.SysPaycolTypeVo;
import com.xjy.system.mapper.SysPaycolTypeMapper;
import com.xjy.system.service.ISysPaycolTypeService;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 收/付款到期提醒方式信息Service业务层处理
 *
 * @author zc
 * @date 2022-02-09
 */
@Service
public class SysPaycolTypeServiceImpl extends ServicePlusImpl<SysPaycolTypeMapper, SysPaycolType> implements ISysPaycolTypeService {

	@Override
	public SysPaycolTypeVo queryById(Long id) {
		return getVoById(id, SysPaycolTypeVo.class);
	}

	@Override
	public TableDataInfo<SysPaycolTypeVo> queryPageList(SysPaycolTypeQueryBo bo) {
		PagePlus<SysPaycolType, SysPaycolTypeVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo), SysPaycolTypeVo.class);
		return PageUtils.buildDataInfo(result);
	}

	@Override
	public List<SysPaycolTypeVo> queryList(SysPaycolTypeQueryBo bo) {
		return listVo(buildQueryWrapper(bo), SysPaycolTypeVo.class);
	}

	private LambdaQueryWrapper<SysPaycolType> buildQueryWrapper(SysPaycolTypeQueryBo bo) {
		Map<String, Object> params = bo.getParams();
		LambdaQueryWrapper<SysPaycolType> lqw = Wrappers.lambdaQuery();
		lqw.eq(StrUtil.isNotBlank(bo.getType()), SysPaycolType::getType, bo.getType());
		return lqw;
	}

	@Override
	public Boolean insertByAddBo(SysPaycolTypeAddBo bo) {
		SysPaycolType add = BeanUtil.toBean(bo, SysPaycolType.class);
		validEntityBeforeSave(add);
		return save(add);
	}

	@Override
	public Boolean updateByEditBo(SysPaycolTypeEditBo bo) {
		SysPaycolType update = BeanUtil.toBean(bo, SysPaycolType.class);
		validEntityBeforeSave(update);
		return updateById(update);
	}

	/**
	 * 保存前的数据校验
	 *
	 * @param entity 实体类数据
	 */
	private void validEntityBeforeSave(SysPaycolType entity) {
		//TODO 做一些数据校验,如唯一约束
	}

	@Override
	public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
		if (isValid) {
			//TODO 做一些业务上的校验,判断是否需要校验
		}
		return removeByIds(ids);
	}
}
